package cz.proks.schoolpupilbook.gae.restlet.resource;

import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_COURSES;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_COURSES_FOR_STUDENT;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_MARKS;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_MARKS_FOR_COURSE_FOR_STUDENT;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_STUDENTS_FOR_COURSE;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_STUDENTS_FOR_PARENT;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_USERS;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_USERS_BY_ROLE;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_USER_COURSE_RELATIONS;
import static cz.proks.schoolpupilbook.shared.restlet.RestMapping.METHOD_LIST_USER_RELATIONS;

import java.util.LinkedList;
import java.util.List;

import org.restlet.resource.Get;

import cz.proks.schoolpupilbook.shared.domain.IsIndexableDomain;


public interface ListResource {
	@Get
	public LinkedList<? extends IsIndexableDomain> list();
		
	public enum ListMethodMapping {
		COURSES(METHOD_LIST_COURSES), 
		USERS(METHOD_LIST_USERS),
		MARKS(METHOD_LIST_MARKS),
		USER_RELATIONS(METHOD_LIST_USER_RELATIONS),
		USER_COURSE_RELATIONS(METHOD_LIST_USER_COURSE_RELATIONS),
		STUDENTS_FOR_COURSE(METHOD_LIST_STUDENTS_FOR_COURSE), 
		STUDENTS_FOR_PARENT(METHOD_LIST_STUDENTS_FOR_PARENT), 
		COURSES_FOR_STUDENT(METHOD_LIST_COURSES_FOR_STUDENT), 
		MARKS_FOR_COURSE_FOR_STUDENT(METHOD_LIST_MARKS_FOR_COURSE_FOR_STUDENT),
		USERS_BY_ROLE(METHOD_LIST_USERS_BY_ROLE);
		
		private String restMapping;
		
		private ListMethodMapping(String restMapping) {
			this.restMapping = restMapping;
		}
		
		public static ListMethodMapping forRestMapping(String restMapping) {
			ListMethodMapping[] actions = values();
			
			for (ListMethodMapping action : actions) {
				if (action.toRestMapping().equals(restMapping))
					return action;
			}
			
			return null;
		}
		
		public String toRestMapping() {
			return restMapping;
		}
	}
}
